// folktale task  处理异步

const fs = require('fs')
const { task } = require('folktale/concurrency/task')
const { split, find } = require('lodash/fp')

function readFile(fileName) { 
  return task(resolve => { 
    fs.readFile(fileName, 'utf-8', function (err, data) { 
      if (err) resolve.reject(err)

      resolve.resolve(data)
    })
  })
}

readFile('package.json')
  .map(split('\n'))
  .map(find(x => x.includes('version')))
  .run()
  .listen({
    onRejected: err => { 
      console.log(err)
    },
    onResolved: data => { 
      console.log(data); // "version": "1.0.0",
    }
  })

  